from waveapi import events
from waveapi import model
from waveapi import robot

from highlight import highlightBlip

version = 3

def OnBlipSubmitted(properties, context):
    """Invoked everytime a blip is submitted"""
    blip = context.GetBlipById(properties['blipId']).GetDocument()
    highlightBlip(blip)

def OnSelfAdded(properties, context):
    """Invoked when the robot has been added."""
    #root_wavelet = context.GetRootWavelet()
    #root_wavelet.CreateBlip().GetDocument().SetText("I'm waveHighlight Robot V%s"%version)
#    root_wavelet.CreateBlip().GetDocument().SetText("I'm waveHighlight Robot V%s"%version)
#    blip = context.GetBlipById(root_wavelet.GetRootBlipId())
#    blip.GetDocument().AppendInlineBlip()
    blip = context.GetBlipById(properties['blipId'])
    #blip.CreateChild().GetDocument().SetText("I'm waveHighlight Robot V%s"%version)
    blipDoc = blip.GetDocument()
    blipDoc.SetText("I'm waveHighlight Robot V%s"%version)
    #wavelet = context.GetWaveletById(properties['waveletId'])
    blip.CreateChild().GetDocument().SetText("I'm waveHighlight Robot V%s again"%version)

    
if __name__ == '__main__':
    myRobot = robot.Robot('waveHighlight',
        image_url='http://wavehighlight.appspot.com/static/images/highlight.gif',
        version='%d'%version,
        profile_url='http://wavehighlight.appspot.com/')
    myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted)
    myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnSelfAdded)
    myRobot.Run()

